//////////////////////////////
//Custom chrome class.
//////////////////////////////
package org.bbdesign.airbuzz{
	import flash.display.*;
	import flash.desktop.*;
	import flash.events.*;
	import flash.filters.*;
	//Tweener classes.
	import caurina.transitions.Tweener;
	import caurina.transitions.properties.FilterShortcuts;
	import caurina.transitions.properties.ColorShortcuts;

	public class Customchrome extends Sprite {
		//////////////////////////////
		//Internal class variables.
		//////////////////////////////
		//Instance.
		private var _appchrome:DisplayObject;
		private var _closebtn:DisplayObject;
		private var _minimizebtn:DisplayObject;
		//Filters.
		private var _glowIn:GlowFilter  = new GlowFilter(0xffffff,0.8,10,10,2,2);
		private var _glowOut:GlowFilter = new GlowFilter(0xffffff,0,10,10,2,2);

		//////////////////////////////
		//Constructor.
		//////////////////////////////
		public function Customchrome() {
			//////////////////////////////
			//Init Tweener color/filters.
			//////////////////////////////
			FilterShortcuts.init();
			ColorShortcuts.init();
			//////////////////////////////

			//////////////////////////////
			//Build chrome.
			//////////////////////////////
			buildChrome();
			//////////////////////////////
		}
		//////////////////////////////

		//////////////////////////////

		//////////////////////////////
		//Private methods.
		//////////////////////////////

		//////////////////////////////

		//////////////////////////////

		//////////////////////////////
		//Build chrome.
		//////////////////////////////
		private function buildChrome():void {
			//Initialize assets.
			//Chrome/background.
			_appchrome = new AppChrome();
			with (_appchrome) {
				x = 325;
				y = 310;
			}
			//Close button.
			_closebtn = new CloseBtn();
			Tweener.addTween(_closebtn, {_color:0xFFFFCC});
			with (_closebtn) {
				alpha = 0.5;
				x = 630;
				y = 18;
			}
			//Minimize button.
			_minimizebtn = new MinimizeBtn();
			Tweener.addTween(_minimizebtn, {_color:0xFFFFCC});
			with (_minimizebtn) {
				alpha = 0.5;
				x = 613;
				y = 22;
			}

			//Add objects to display list.
			addChild(_appchrome);
			addChild(_minimizebtn);
			addChild(_closebtn);
			//Apply listeners.
			//Click/drag.
			_appchrome.addEventListener(MouseEvent.MOUSE_DOWN, dragChromeHandler);
			_closebtn.addEventListener(MouseEvent.CLICK, closeBtnHandler);
			_minimizebtn.addEventListener(MouseEvent.CLICK, minimizeBtnHandler);
			//Over/out.
			_closebtn.addEventListener(MouseEvent.MOUSE_OVER, closeBtnRollOverHandler);
			_closebtn.addEventListener(MouseEvent.MOUSE_OUT, closeBtnRollOutHandler);
			_minimizebtn.addEventListener(MouseEvent.MOUSE_OVER, minimizeRollOverBtnHandler);
			_minimizebtn.addEventListener(MouseEvent.MOUSE_OUT, minimizeRollOutBtnHandler);
		}
		//////////////////////////////

		//////////////////////////////
		//Event handlers.
		//////////////////////////////
		//Drag chrome.
		private function dragChromeHandler(e:MouseEvent):void {
			stage.nativeWindow.startMove();
		}
		//Close.
		private function closeBtnHandler(e:MouseEvent):void {
			NativeApplication.nativeApplication.exit();
		}
		private function closeBtnRollOverHandler(e:MouseEvent):void {
			Tweener.addTween(_closebtn, { _color:0xffffff, time:0.5, transition:"easeOutSine"} );
			Tweener.addTween(_closebtn, { _filter:_glowIn, time:1 } );
		}
		private function closeBtnRollOutHandler(e:MouseEvent):void {
			Tweener.addTween(_closebtn, { _color:0xFFFFCC, time:0.5, transition:"easeOutSine"} );
			Tweener.addTween(_closebtn, { _filter:_glowOut, time:1 });
		}
		//Minimize.
		private function minimizeBtnHandler(e:MouseEvent):void {
			stage.nativeWindow.minimize();
		}
		private function minimizeRollOverBtnHandler(e:MouseEvent):void {
			Tweener.addTween(_minimizebtn, { _color:0xffffff, time:0.5, transition:"easeOutSine"} );
			Tweener.addTween(_minimizebtn, { _filter:_glowIn, time:1 } );
		}
		private function minimizeRollOutBtnHandler(e:MouseEvent):void {
			Tweener.addTween(_minimizebtn, { _color:0xFFFFCC, time:0.5, transition:"easeOutSine"} );
			Tweener.addTween(_minimizebtn, { _filter:_glowOut, time:1 });
		}
		//////////////////////////////

	}
}

